<!DOCTYPE html>
<html lang="zh-cn" xmlns="http://www.w3.org/1999/xhtml" xmlns:th="http://www.thymeleaf.org">
<head>
<title th:text="|#{customer.systemTitle}-内容管理-友情链接|">图灵谷</title>
<div th:replace="fragments/head_admin">head</div>
<!--/***** 当前页css  start *****/-->
<!--/***** 当前页css  end *****/-->
</head>
<body>
	<div class="layui-layout layui-layout-admin">
		<div th:replace="fragments/nav_admin">导航栏</div>
		<div th:replace="fragments/menu_admin::menu(parent=content,child=friendlink)">菜单栏</div>
		<!--/*******内容*******/-->
		<div class="layui-body">
			<div class="layui-main">
				<!--/***** 面包屑 *****/-->
				<div class="layui-elem-quote" style="margin-top: 10px;">
					<span class="layui-breadcrumb"> <a><cite>内容管理</cite></a><a th:href="@{/admin/m/ext/friendlink/list.gsp}">友情链接</a><a><cite>新增</cite></a>
					</span>
				</div>
				<!--/*******操作*******/-->
				<form th:action="@{/admin/m/ext/friendlink/add.gsp}" id="addForm" role="form" method="post" class="layui-form">
					<fieldset class="layui-elem-field layui-field-title">
						<legend>友情链接-新增</legend>
					</fieldset>
					<div class="layui-form-item">
						<label class="layui-form-label">类型：<span style="color: red">*</span></label>
						<div class="layui-input-block">
							<select id="typeId" name="typeId" lay-verify="required"><option th:if="${result.size()<=0}" value="">暂无</option>
								<option th:each="data : ${result}" th:value="${data.id}" th:text="${data.typeName}"></option></select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">网站名称：<span style="color: red">*</span></label>
						<div class="layui-input-block">
							<input type="text" name="flName" required lay-verify="flName" placeholder="请输入网站名称" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">网站地址：</label>
						<div class="layui-input-block">
							<input type="text" name="flUrl" lay-verify="res" placeholder="请输入网站地址" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">网站logo：</label>
						<div class="layui-input-block">
							<img id="imgShow" width="164"><br /> <input id="flLogo" type="file" name="file" class="layui-upload-file">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">站长邮箱：</label>
						<div class="layui-input-block">
							<input type="text" name="flEmail" lay-verify="flEmail" placeholder="请输入站长Email" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">是否推荐：</label>
						<div class="layui-input-block">
							<select id="recommend" name="recommend" lay-verify="required"><option value="1">是</option>
								<option value="2">否</option></select>
						</div>
					</div>
					<div class="layui-form-item">
						<label class="layui-form-label">排序：<span style="color: red">*</span></label>
						<div class="layui-input-block">
							<input type="number" name="sortOrder" required lay-verify="number" min="1" max="99" placeholder="请输入排序" autocomplete="off" class="layui-input">
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">描述：</label>
						<div class="layui-input-block">
							<textarea name="description" placeholder="最多输入140字" lay-verify="description" rows="3" class="layui-textarea"></textarea>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<button class="layui-btn" lay-submit="" lay-filter="submit">立即提交</button>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<div th:replace="fragments/footer_admin">底部版权信息等</div>
	</div>
</body>
<div th:replace="fragments/import_js_admin">引入js</div>
<!--/***** 当前页js start *****/-->
<script th:src="@{/resources/js/common/formBuilder.js}"></script>
<script th:inline="javascript">
    /*<![CDATA[*/
    var form = layui.form();
    var $ = layui.jquery;
    
    layui.use('upload', function() {
        url = BASE_URL + 'admin/m/base/image/uploadImg';
        tg_upload("flLogo", url);
    });
    
    function tg_upload(id, url) {
        $("#" + id).after('<input id="Input'+id+'" type="text" value="" name="'+id+'" hidden="hidden">');
        var fileName;
        //文件上传
        layui.upload({
            url : url,//上传接口
            elem : '#' + id,
            ext : 'jpg|png|gif', //图片格式限制
            before : function(input) {
                layer.msg('文件上传中');
            },
            success : function(res) { //上传成功后的回调
                if(res.success){
                    $("#" + id).parent().next().text("上传成功");
                    $("#Input" + id).attr("value", res.obj);
                    $("#imgShow").attr("src", res.path);
                }
            }
        });
    }
    
  //自定义验证规则
    var rules = {
        flName : function(value) {
            if (value.length <= 0 || value.length > 20) {
                return '网站名称必填';
            }else if(value.length > 20){
                return '网站名称不能超过20个字符';
            }
        },
        flUrl : function(value) {
            if (value.length > 0) {
                if(!/(^#)|(^http(s*):\/\/[^\s]+\.[^\s]+)/.test(value)){
                    return '网站地址格式不正确'
                }
            }
        },
        flEmail : function(value) {
            if(value.length > 0){
                if (!(/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(value))) {
                    return '邮箱格式不正确';
                } else if (value.length > 35) {
                    return '邮箱太长了，确定这是个真实的邮箱地址吗！';
                }
            }
        },
        description : function(value) {
            if (value.length > 140) {
                return '描述不能超过140个字符';
            }
        }
    };
    form.verify(rules);
    /*]]>*/
</script>
<!--/***** 当前页js end *****/-->
</html>